package com.prime.tutorial.moviestore.view.auth;

import com.prime.tutorial.moviestore.Constants;
import com.prime.tutorial.moviestore.domain.Users;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.faces.context.FacesContext;
import java.io.Serializable;

/**
 * Provides current users, stored in session
 * Created by IntelliJ IDEA.
 * Users: me
 * Date: 25 лют 2010
 * Time: 22:58:55
 * @author iryna.masyuk
 */

@Component("currentUser")
@Scope("request")
public class CurrentUser implements Serializable {
    Users users;

    public CurrentUser(){
        //TODO probably some check, whether users has right to access this page
        FacesContext context = FacesContext.getCurrentInstance();
        users = (Users)(context.getExternalContext().getSessionMap().get(Constants.USER_SESSION_KEY));
    }

    public Users getUser(){
         return users;
    }

}
